<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>缺勤管理界面</title>
		<link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
		<script src="../js/jquery-3.5.1.js"></script>
		<script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
	</head>
	<body>
		<div class="container">
			<nav class="navbar navbar-default">
				<div class="container-fluid ">
					<!-- Brand and toggle get grouped for better mobile display -->
					<div class="navbar-header ">
						<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
						 aria-expanded="false">
							<span class="sr-only">Toggle navigation</span>
							<span class="icon-bar"></span>
							<span class="icon-bar"></span>
							<span class="icon-bar"></span>
						</button>
						<h2>缺勤管理</h2>
						<!-- <a class="navbar-brand" href="#">书本商城</a> -->
					</div>

					<!-- Collect the nav links, forms, and other content for toggling -->

				</div><!-- /.container-fluid -->
			</nav>
			<div class="panel panel-info">
				<div class="panel-heading">
					<button type="button" class="btn btn-success btn-sm" onclick="add()">添加</button>
					<div class="pull-right">
						<!-- Single button -->
						<div class="btn-group">
							<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
							 aria-expanded="false">
								全部宿舍楼 <span class="caret"></span>
							</button>
							<ul class="dropdown-menu">
								<li><a href="#">Action</a></li>
								<li><a href="#">Another action</a></li>
								<li><a href="#">Something else here</a></li>
								<li role="separator" class="divider"></li>
								<li><a href="#">Separated link</a></li>
							</ul>
						</div>
						<div class="btn-group">

							<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
							 aria-expanded="false">
								姓名<span class="caret"></span>
							</button>
							<ul class="dropdown-menu">
								<li><a href="#">Action</a></li>
								<li><a href="#">Another action</a></li>
								<li><a href="#">Something else here</a></li>
								<li role="separator" class="divider"></li>
								<li><a href="#">Separated link</a></li>
							</ul>
						</div>
						<form style="display: inline-block;" class="form-inline">

							<div class="form-group">
								<input type="text" class="form-control input-sm" id="ipt_top">
							</div>

							<button type="button" class="btn btn-default btn-sm btn-primary" onclick="search()">搜索</button>
						</form>

					</div>
				</div>
				<div class="panel-body">
					<table class="table table-striped table-bordered table-hover" id="mytable">
						<thead>
							<tr>
								<th>日期</th>
								<th>学号</th>
								<th>姓名</th>
								<th>宿舍楼</th>
								<th>寝室</th>
								<th>备注</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>

						</tbody>
					</table>
					<nav class="text-center">
						<ul class="pagination">
							<li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
							<li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
							<li><a href="#">2 </a></li>
							<li><a href="#">3 </a></li>
							<li><a href="#" aria-label="Next"><span aria-hidden="true">»</span></a></li>
						</ul>
					</nav>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			let quearr1 = [{
				id: 0,
				que_date:"2020-02-02",
				name:"2017096012691",
				Fullname: "子鱼",
				address: "1栋",
				dorm: 212,
				beizhu: "感冒了"
			}]
			let quearr = JSON.parse(localStorage.getItem("quearr"));
			if (!quearr) {
				quearr = quearr1;
				localStorage.setItem("quearr", JSON.stringify(quearr));
			};
			console.log(quearr);
			let $tbody = $("table").find("tbody");

			function load(search) {
				for (let index in quearr) {
					//搜索判断
					let item = quearr[index];
					if (search && item.name.toLowerCase().indexOf(search.toLowerCase()) === -1) {
						continue;
					}
					let tr =
						`
					<tr>
					<td>${item.que_date}</td>
					<td>${item.name}</td>
					<td>${item.Fullname}</td>
					<td>${item.address}</td>
					<td>${item.dorm}</td>
					<td>${item.beizhu}</td>
					<td>
					<button type="button" class="btn btn-danger btn-sm" onclick="del(${index})">删除</button>
					<button type="button" class="btn btn-info btn-sm" onclick="edit(${index})">编辑</button>
					</td>
					</tr>
					`;
					$tbody.append(tr);
				}
			}
			//添加
			function add() {
				location.href = "queqin_add.html"
			}
			//删除
			function del(index) {
				quearr.splice(index, 1);
				$tbody.empty();
				load();
				localStorage.setItem("quearr", JSON.stringify(quearr));
			}
			//编辑
			function edit(index) {
				let item1 = quearr[index];
				sessionStorage.setItem("queqin_add", JSON.stringify(item1));
				quearr.splice(index, 1);
				localStorage.setItem("quearr", JSON.stringify(quearr));
				location.href = "queqin_add.html";
			}
			//搜索
			function search() {
				//获取输入框内容id="ipt_top"
				let search = $("input[id='ipt_top']").val();
				$tbody.empty();
				load(search);
			}
			load();
		</script>
	</body>
</html>
